<?php
/**
*
* @package ppkBB3cker
* @version $Id: top_by_torrents.php 1.000 2010-04-20 10:35:00 PPK $
* @copyright (c) 2010 PPK
* @Based on Top v.2.0 for tt.u-l.ru (c) Boec
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

//TOP_BY_TORRENTS
$sql = "SELECT tor.*, t.*, u.username, u.user_id, f.forum_id, f.forum_name, t.topic_title, t.topic_id, u.user_regdate, tor.times_completed
	FROM ". TRACKER_TORRENTS_TABLE ." tor, " . TOPICS_TABLE . " t , " . FORUMS_TABLE. " f , " . USERS_TABLE . " u
	WHERE tor.topic_id = t.topic_id
	AND tor.poster_id = u.user_id
	AND t.forum_id = f.forum_id
	ORDER BY tor.times_completed DESC
	LIMIT $top_limit";
if( !($result = $db->sql_query($sql, $config['ppkbb_tstat_ctime']*60)) )
{
	//message_die(GENERAL_ERROR, "Could not query torrent", '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
	$i = 0;
	do
	{
		$username = $row['username'];
		$user_id = $row['user_id'];
		$forum_name = $row ['forum_name'];
		$forum_id = $row['forum_id'];
		$poster_id = $row['user_id'];
		$topic_title = $row['topic_title'];
		$topic_id = $row['topic_id'];
		$complete = $row['times_completed'];
		$reg_time = $user->format_date($row['added']);
		$row_class = ( !($i % 2) ) ? 'row1' : 'row2';

		$template->assign_block_vars('torrentsrow', array(
			'ROW_NUMBER' => $i + ( $start + 1 ),
			'ROW_CLASS' => $row_class,
			'USERNAME' => $username,
			'FORUM_NAME' => $forum_name,
			'FORUM_HREF' => append_sid("viewforum.$phpEx?f=". $row['forum_id']),
			'REG_TIME' => $reg_time,
			'COMPLETE_COUNT' => $complete,
			'TOPIC_TITLE' => censor_text($topic_title),
			'TOPIC_HREF'   => append_sid("viewtopic.$phpEx?t=". $row['topic_id']),
			'U_VIEWPROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"))
		);
		$i++;
	}
	while ( $row = $db->sql_fetchrow($result) );
	$db->sql_freeresult($result);

}

?>
